package com.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mapper.RecordsMapper;
import com.model.Records;
import com.util.PageBean;
@Service
public class RecordsServiceImpl implements RecordsService{
        
	@Autowired
	private RecordsMapper recordsMapper;

	//查询多条记录
	public List<Records> queryRecordsList(Records records,PageBean page) throws Exception {
		Map<String, Object> map =getQueryMap(records, page);
		
		List<Records> getRecords = recordsMapper.query(map);
		
		return getRecords;
	}
	
	//得到记录总数
	@Override
	public int getCount(Records records) {
		Map<String, Object> map = getQueryMap(records, null);
		int count = recordsMapper.getCount(map);
		return count;
	}
	
	private Map<String, Object> getQueryMap(Records records,PageBean page){
		Map<String, Object> map = new HashMap<String, Object>();
		if(records!=null){
			map.put("id", records.getId());
			map.put("sno", records.getSno());
			map.put("rtype", records.getRtype());
			map.put("rmemo", records.getRmemo());
			map.put("rtime", records.getRtime());
			map.put("sort", records.getSort());
			map.put("condition", records.getCondition());

		}
		PageBean.setPageMap(map, page);
		return map;
	}
		
	//添加
	public int insertRecords(Records records) throws Exception {
		return recordsMapper.insertRecords(records);
	}

	//根据ID删除
	public int deleteRecords(int id) throws Exception {
		return recordsMapper.deleteRecords(id);
	}

	//更新
	public int updateRecords(Records records) throws Exception {
		return recordsMapper.updateRecords(records);
	}
	
	//根据ID得到对应的记录
	public Records queryRecordsById(int id) throws Exception {
		Records po =  recordsMapper.queryRecordsById(id);
		return po;
	}
}

